package intro;

public class GcdTest {
    public static int gcd_b_force(int a, int b) {
        int min = Math.min(a, b);
        while (min-- >= 1) {
            if (a % min == 0 && b % min == 0) {
                return min;
            }
        }
        return 1;
    }

    public static int gcd_subtract(int a, int b) {
        // 保持a比b大
        if(a < b) {
            int tmp = a;
            a = b;
            b = tmp;
        }

        while (b > 0) {
            int tmp = a - b;
            a = b;
            b = tmp;
        }
        return a;
    }

    public static int gcd_devide(int a, int b) {
        // 保持a比b大
        if(a < b) {
            int tmp = a;
            a = b;
            b = tmp;
        }

        while (b > 0) {
            int tmp = a % b;
            a = b;
            b = tmp;
        }
        return a;
    }

    public static void main(String[] args) {
        int a = 3600;
        int b = 2400;
        System.out.println(gcd_b_force(a, b));

        System.out.println(gcd_subtract(a, b));

        System.out.println(gcd_devide(a, b));
    }
}
